package com.qf.lanzhou.shop.admin.controller;

import com.qf.lanzhou.shop.admin.exceptions.BaseExceptions;
import com.qf.lanzhou.shop.admin.service.PageAdminService;
import com.qf.lanzhou.shop.pojo.entity.Goods;
import com.qf.lanzhou.shop.pojo.vo.BaseRespVO;
import com.qf.lanzhou.shop.util.UnloginCheckUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author Yeach-chen
 * @ClassName PageAdminController
 */
@Api(tags = "后台管理商品修改入口")
@Controller
public class PageAdminController extends BaseController {
    @Autowired
    private PageAdminService pageAdminService;
    @RequestMapping("/get_page_goods")
    @ResponseBody
    public BaseRespVO getGoodsAll(Integer pageIndex, HttpServletRequest req){
        if (UnloginCheckUtil.checkLogin(req)){
            throw new BaseExceptions(300,"用户未登录");
        }
        if (pageIndex==null){
            pageIndex=1;
        }
        List<Goods> goods = pageAdminService.getGoodsShow(pageIndex);
        return convertSuccessResult(goods);
    }
    @RequestMapping("/get_page_count")
    @ResponseBody
    public BaseRespVO getCount(){
        int count = pageAdminService.getCount();
        return convertSuccessResult(count);
    }
}
